home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-17 | 6.1 KB | 238 lines | [TEXT/CWIE] |
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
- #include <DeskBus.h>
- #include <Retrace.h>
- #include <Speech.h>
-
- #include "filter.h"
- #include "adb.h"
- #include "speech.h"
- #include "pref.h"
- #include "globals.h"
- #include "command.h"
- #include "menu.h"
- #include "aerecord.h"
- #include "about.h"
-
- #define ACTION_FUNC(cmd) static void Action##cmd (CommandType command, void* refCon)
- #define ACTION_ENTRY(cmd) cmd, Action##cmd
-
- ACTION_FUNC(SpeakCharsCmd);
- ACTION_FUNC(SpeakWordsCmd);
- ACTION_FUNC(SpeakSentencesCmd);
- ACTION_FUNC(QuitCmd);
- ACTION_FUNC(VoiceCmd);
- ACTION_FUNC(OpenDescAccCmd);
- ACTION_FUNC(AboutCmd);
-
- static CommandEntry gCommandTable[] = {
- ACTION_ENTRY(SpeakCharsCmd),
- ACTION_ENTRY(SpeakWordsCmd),
- ACTION_ENTRY(SpeakSentencesCmd),
- ACTION_ENTRY(QuitCmd),
- ACTION_ENTRY(VoiceCmd),
- ACTION_ENTRY(OpenDescAccCmd),
- ACTION_ENTRY(AboutCmd)
- };
- #define kNumCommands sizeof(gCommandTable)/sizeof(CommandEntry)
-
-
- static void SetValue(CommandType command, long* var, void* refCon);
-
- // * ****************************************************************************** *
- // * ProcessCommand
- // * Process the low level commands of the app
- // * ****************************************************************************** *
- void ProcessCommand(CommandType command, void* param)
- {
- CommandEntry* curcmd;
- short count;
-
- for (count = 0, curcmd = gCommandTable; count < kNumCommands; count++, curcmd++) {
- if ((command & kCommandMask) == (curcmd->command & kCommandMask)) {
- (*curcmd->action)(command, param);
- return;
- }
- }
- }
-
- // * ****************************************************************************** *
- // * ActionSpeakCharsCmd
- // * Handle a SpeakChars command
- // * ****************************************************************************** *
- static void ActionSpeakCharsCmd(CommandType command, void* refCon)
- {
- MenuHandle menuHandle;
- long oldvalue, newvalue;
- OSErr err;
-
- oldvalue = newvalue = (**gPrefs).speakChars;
- SetValue(command, &newvalue, refCon);
- if (newvalue == oldvalue)
- return;
-
- (**gPrefs).speakChars = newvalue;
- gCharIndex = 0;
-
- menuHandle = GetMenu(kSpeakMenuID);
- CheckItem(menuHandle, kSpeakCharsItem, (**gPrefs).speakChars);
- if ((**gPrefs).speakChars) {
- InstallADBServiceRoutine(gKeyBoardADBAddress);
- }
- else {
- RemoveADBServiceRoutine(gKeyBoardADBAddress);
- }
-
- err = IssueSetSpeakChars();
- }
-
-
- // * ****************************************************************************** *
- // * ActionSpeakWordsCmd
- // * Handle a SpeakWords command
- // * ****************************************************************************** *
- static void ActionSpeakWordsCmd(CommandType command, void* refCon)
- {
-
- MenuHandle menuHandle;
- long oldvalue, newvalue;
- OSErr err;
-
- oldvalue = newvalue = (**gPrefs).speakWords;
- SetValue(command, &newvalue, refCon);
- if (newvalue == oldvalue)
- return;
-
- (**gPrefs).speakWords = newvalue;
-
- gWordIndex = 0;
- menuHandle = GetMenu(kSpeakMenuID);
- CheckItem(menuHandle, kSpeakWordsItem, (**gPrefs).speakWords);
-
- err = IssueSetSpeakWords();
- }
-
-
- // * ****************************************************************************** *
- // * ActionSpeakSentencesCmd
- // * Handle a SpeakSentences command
- // * ****************************************************************************** *
- static void ActionSpeakSentencesCmd(CommandType command, void* refCon)
- {
-
- MenuHandle menuHandle;
- long oldvalue, newvalue;
- OSErr err;
-
- oldvalue = newvalue = (**gPrefs).speakSentence;
- SetValue(command, &newvalue, refCon);
- if (newvalue == oldvalue)
- return;
-
- (**gPrefs).speakSentence = newvalue;
- gSentenceIndex = 0;
-
- menuHandle = GetMenu(kSpeakMenuID);
- CheckItem(menuHandle, kSpeakSentenceItem, (**gPrefs).speakSentence);
- err = IssueSetSpeakSentences();
- }
-
- // * ****************************************************************************** *
- // * ActionQuitCmd
- // * Handle a Quit command
- // * ****************************************************************************** *
- static void ActionQuitCmd(CommandType command, void* refCon)
- {
-
- long oldvalue, newvalue;
-
- oldvalue = newvalue = gQuitting;
- SetValue(command, &newvalue, refCon);
- if (oldvalue != newvalue) {
- gQuitting = (newvalue != 0);
- IssueQuitCommand();
- }
- }
-
- // * ****************************************************************************** *
- // * ActionVoiceCmd
- // * Handle a change voice command
- // * ****************************************************************************** *
- static void ActionVoiceCmd(CommandType command, void* refCon)
- {
- Str255 oldvalue;
- OSErr err;
-
- BlockMoveData((**gPrefs).voice, oldvalue, sizeof(Str255));
- SetValue(command, (long*)(**gPrefs).voice, refCon);
- if (EqualString((**gPrefs).voice, oldvalue, false, false))
- return;
-
- err = SetDefaultVoice();
- err = IssueSetVoice();
- }
-
-
- // * ****************************************************************************** *
- // * OpenDescAccCmd
- // * Handle a OpenDeskAcc command
- // * ****************************************************************************** *
- static void ActionOpenDescAccCmd(CommandType command, void* refCon)
- {
- Str255 deskName;
-
- SetValue(command, (long*)deskName, refCon);
- OpenDeskAcc(deskName);
-
- }
-
- // * ****************************************************************************** *
- // * AboutCmd
- // * Handle a about command
- // * ****************************************************************************** *
- static void ActionAboutCmd(CommandType command, void* refCon)
- {
- #pragma unused(command, refCon)
- DoAboutBox();
- }
-
- // * ****************************************************************************** *
- // * SetValue
- // * change a commands value
- // * ****************************************************************************** *
- static void SetValue(CommandType command, long* var, void* refCon)
- {
- char value;
-
- value = command & kValueMask;
-
- if (value >= kSetValMin && value <= kSetValMax) {
- *var = ((value - kSetValMin)) & kValueMask;
- return;
- }
- else {
- switch (value) {
- case kToggleValue:
- *var = !(*var);
- return;
-
- case kIncValue:
- (*var)++;
- return;
-
- case kDecValue:
- (*var)++;
- return;
-
- case kStringValue:
- BlockMoveData(refCon, var, *((char*)refCon) + 1);
- return;
-
- default:
- break;
- }
- }
- }
-